package com.maxlen.order.config;

import com.maxlen.common.constant.LoginConstant;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * 配置远程调用 member 设置请求头，将 token 放入请求头中
 */
//@Configuration
//public class FeignConfiguration implements RequestInterceptor {
//
//    @Override
//    public void apply(RequestTemplate requestTemplate) {
//        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        System.out.println(attributes);
//        if (null != attributes) {
//            HttpServletRequest request = attributes.getRequest();
//            String header = request.getHeader(LoginConstant.TOKEN);
//            System.out.println(header);
//            if(StringUtils.hasText(header)){
//                requestTemplate.header(LoginConstant.TOKEN, header);
//            }
//        }
//    }
//}
